//
//  OriginalView.m
//  01 微博
//
//  Created by zhoup on 16/5/28.
//  Copyright © 2016年 zhoup. All rights reserved.
//

#import "OriginalView.h"

@interface OriginalView()

/**
 *  头像
 */
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
/**
 *  昵称
 */
@property (weak, nonatomic) IBOutlet UILabel *nameLable;
/**
 *  时间
 */
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
/**
 *  来源
 */
@property (weak, nonatomic) IBOutlet UILabel *sourceLabel;
/**
 *  正文
 */
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
/**
 *  会员图标
 */
@property (weak, nonatomic) IBOutlet UIImageView *vipView;

@property (weak, nonatomic) IBOutlet UIImageView *photoView;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *picHeight;

@end

@implementation OriginalView


-(void)setStatus:(IWStatus *)status
{
    _status = status;
    // 头像
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:_status.user.profile_image_url] placeholderImage:[UIImage imageNamed:@"avatar_default_big"]];
    
    // 昵称
    self.nameLable.text = _status.user.name;
    
    // 会员图标
    if ([_status.user isVip]) {
        // 是会员
        self.vipView.hidden = NO;
        // 设置会员图标
        // 拼接会员图标图片名称
        NSString *imageName = [NSString stringWithFormat:@"common_icon_membership_level%d", _status.user.mbrank.intValue];
        self.vipView.image = [UIImage imageNamed:imageName];
        
        // 设置昵称颜色
        self.nameLable.textColor = [UIColor orangeColor];
    }else
    {
        // 注意, cell的重用问题
        // 1.隐藏会员图标
        self.vipView.hidden = YES;
        // 2.还原昵称的颜色
        self.nameLable.textColor = [UIColor blackColor];
    }
    // 时间
    self.timeLabel.text = _status.created_at;
    // 来源
    self.sourceLabel.text = _status.source;
    // 正文
    self.contentLabel.text = _status.text;
    // 2.设置数据
    if (status.pic_urls.count >0) {
        NSDictionary *photo = status.pic_urls[0];
        
        NSURL *imageUrl = [NSURL URLWithString:photo[@"thumbnail_pic"]];
        
        // 1.下载图片
        [self.photoView sd_setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@"avatar_default_big"]];
    }
    else
    {
        self.picHeight.constant = 0;
    }

}
@end
